﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Luminal;

namespace Luminoise
{
    public class Min : Module
    {
        static int instanceCount = 0;
        int instanceIndex;

        public Module RightSide { get; private set; }
        public Module LeftSide { get; private set; }

        public override string FunctionName
        {
            get { return "cl_min" + instanceIndex.ToString(); }
        }

        public override string GetCode()
        {
            return RightSide.GetCode() + LeftSide.GetCode() +
@"#ifndef " + FunctionName.ToUpper() + @"
#define " + FunctionName.ToUpper() + @"

float " + FunctionName + @"(__global int *perm, Single3 input)
{
    return min(" + LeftSide.FunctionName + @"(perm, input), " + RightSide.FunctionName + @"(perm, input));
}

#endif

";
        }

        public Min(Module ls, Module rs)
        {
            LeftSide = ls;
            RightSide = rs;

            instanceIndex = instanceCount;
            instanceCount++;
        }
    }
}
